//
//  QTTPublicAlertView.m
//  QuTouTiao
//
//  Created by 杨杨子 on 2018/6/24.
//  Copyright © 2018年 杨杨子. All rights reserved.
//

#import "QTTPublicAlertView.h"
@interface QTTPublicAlertView()
@property (weak, nonatomic) IBOutlet UIView *backView;
@property (weak, nonatomic) IBOutlet UILabel *tittleLb;
@property (weak, nonatomic) IBOutlet UIButton *leftBtn;
- (IBAction)leftBtnAction:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
- (IBAction)rightBtnAction:(id)sender;
@property (nonatomic,strong) ActionBlock leftBlock;
@property (nonatomic,strong) ActionBlock rightBlock;

@end
@implementation QTTPublicAlertView
//-(instancetype)initWithCoder:(NSCoder *)aDecoder{
//
//    self = [super initWithCoder:aDecoder];
//    if (self) {
//
//    }
//    return self;
//}
//-(instancetype)initWithCoder:(NSCoder *)aDecoder
//                   AndTittle:(NSString *)tittle
//               AndLeftBtnStr:(NSString *)leftStr
//                 AndRightStr:(NSString *)rightStr
//                AndLeftBlock:(ActionBlock)leftBlock
//               AndRightBlock:(ActionBlock)rightBlock
-(void)awakeFromNibAndTittle:(NSString *)tittle AndLeftBtnStr:(NSString *)leftStr AndRightStr:(NSString *)rightStr AndLeftBlock:(ActionBlock)leftBlock AndRightBlock:(ActionBlock)rightBlock AndFatherView:(UIView *)fatherView{
        [super awakeFromNib];
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
//        self.backView.layer.cornerRadius = 10;
//        self.backView.layer.borderWidth = 1.0;
//        self.backView.layer.masksToBounds = YES;
    [self.backView setCornerRadius:10.0 AndBorderColor:[UIColor blackColor] AndBorderWidth:1.0];
        self.backView.backgroundColor = [UIColor whiteColor];
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.2];
        self.tittleLb.text = tittle;
        [self.leftBtn setTitle:leftStr forState:UIControlStateNormal];
        [self.rightBtn setTitle:rightStr forState:UIControlStateNormal];
        self.leftBlock = leftBlock;
        self.rightBlock = rightBlock;
    [fatherView addSubview:self];
   __weak typeof (self) weakSelf = self;
    [self viewTapBlock:^{
        [weakSelf removeFromSuperview];
    }];
}

- (IBAction)leftBtnAction:(id)sender{
    [self removeFromSuperview];
    if (self.leftBlock) {
        self.leftBlock();
    }
}
- (IBAction)rightBtnAction:(id)sender {
    [self removeFromSuperview];
    if (self.rightBlock) {
        self.rightBlock();
    }
}
@end
